package cn.fzkj.gulimall.auth.strategy.factory;

import cn.fzkj.gulimall.auth.exception.UnsupportedLoginTypeException;
import cn.fzkj.gulimall.auth.strategy.login.GiteeStrategy;
import cn.fzkj.gulimall.auth.strategy.login.LoginStrategy;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @DESCRIPTION
 * @Author yaya
 * @DATE 2022/8/27
 */
public class LoginStrategyFactory {

    @Autowired
    static List<LoginStrategy> strategyList = new ArrayList(){{
        this.add(new GiteeStrategy());
    }};


    public static LoginStrategy getStrategy(String type) {
        for (LoginStrategy strategy : strategyList) {
            if (strategy.supportType().name().equalsIgnoreCase(type))
                return strategy;
        }
        throw new UnsupportedLoginTypeException();
    }
}
